var Weapon = require("Weapon");
var EnemyDamager = require("EnemyDamager");
var UIController = require("UIController");

cc.Class({
    extends: Weapon,

    properties: {
        rotateSpeed: 1,

		starHolder: cc.Node,
        startoSpawn: cc.Node,

        stayTime: 0,
        hiddenTime: 0,

        spawnCounter: 0,

        damager: EnemyDamager,
    },

    // LIFE-CYCLE CALLBACKS:

    start () {
        this.setStats();
        this.spawnCounter = this.stayTime;


        // 暂定
        let stay = cc.tween(this.star)
        .call(() => {
            this.startoSpawn.active = true;
        })
        .to(this.stayTime, {scale: 1})
        .delay(this.stayTime);
        
        let hidden = cc.tween(this.star)
        .to(this.hiddenTime, {scale: 0.1})
        .call(() => {
            this.startoSpawn.active = false;
        })
        .delay(this.hiddenTime);
        
        let tween = cc.tween(this.node).sequence(stay, hidden);
        cc.tween(this.node).repeatForever(tween).start();
    },

    update (dt) {
        this.starHolder.angle -= this.rotateSpeed * dt * this.stats[this.weaponLevel].speed;


        if (this.statsUpdated == true) {
            this.statsUpdated = false;

            this.setStats();
        }
    },

    setStats () {
        this.damager.damageAmount = this.stats[this.weaponLevel].damage;

        //this.damager.lifeTime = this.stats[this.weaponLevel].timeBetweenAttacks;

        this.startoSpawn.scale *= this.stats[this.weaponLevel].range;

        this.hiddenTime = this.stats[this.weaponLevel].timeBetweenAttacks;

        this.stayTime = this.stats[this.weaponLevel].duration;
    },
});
